package main

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"time"
)

var ctx = context.Background()

/*
TTL(),PTTL():获取有效期
TTL()方法可以获取某个键的剩余有效期
*/

func main() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "81.68.186.20:6379",
		Password: "ffdd2021@",
		DB:       0,
	})
	if rdb != nil {
		fmt.Println("创建成功")
		defer rdb.Close()
	}
	s, err := rdb.Set(ctx, "name", "a", 1*time.Minute).Result()
	if err != nil {
		fmt.Println("插入失败")
	}
	fmt.Println(s)
	d, err := rdb.TTL(ctx, "name").Result()
	if err != nil {
		panic(err)
	}
	fmt.Println("d = ", d)

}
